import type { ConsultOrderItem, ConsultOrderListParams, ConsultOrderPage, ConsultOrderPreData, ConsultOrderPreParams, DoctorPage, FollowType, Image, KnowledgePage, KnowledgeParams, PageParams, PartialConsult, TopDep } from "@/types/consult";
import type { getPatirntType } from "@/types/user";
import { request } from "@/utils/request";

/**
 * 首页-查询推荐/减脂/饮食健康/关注页面--百科文章列表
 * @param params 
 * @returns 
 */
export const getKnowledgeListAPI = (params: KnowledgeParams) =>
  request<KnowledgePage>('/patient/home/knowledge', 'GET', params)


/**
 * 首页-关注的医生列表
 * @param params 
 * @returns 
 */
export const getDoctorListAPI = (params: PageParams) =>
  request<DoctorPage>('/home/page/doc', 'GET', params)

/**
 * 关注-关注操作
 * @param id 
 * @param type 
 * @returns 
 */
export const followDoctorAPI = (id: string, type: FollowType = 'doc') =>
  request('/like', 'POST', { id, type })

/**
 * 获取科室列表
 * @returns 
 */
export const getDepAllAPI = () => 
  request<TopDep[]>('/dep/all')

/**
 * 上传文件/图片
 * @param file 
 * @returns 
 */
export const updataImageAPI = (file: File) => {
  // 实例化formData对象
  const fd = new FormData()
  fd.append('file', file)
  return request<Image>('/upload', 'POST', fd)
}

/**
 * 问诊-支付页面-计算就诊信息和抵扣信息
 * @param params 
 * @returns 
 */
export const getPreConsultOrderAPI = (params: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)

/**
 * 问诊-查询患者详情
 * @param id 患者id
 * @returns Prmoise对象
 */
export const getPatientInfoAPI = (id: string) =>
  request<getPatirntType>(`/patient/info/${id}`)

/**
 * 问诊-保存/修改问诊订单
 * @param data 请求对象
 * @returns Prmoise对象
 */
export const createOrderIdAPI = (data: PartialConsult) => 
  request<{id: string}>('/patient/consult/order', 'POST', data)

/**
 * 订单-支付接口
 * @param params 
 * @returns 
 */
export const getOrderPayAPI = (params: {
  paymentMethod: 0 | 1
  orderId: string
  payCallback: string
}) => 
  request<{payUrl: string}>('/patient/consult/pay', 'POST', params)


/**
 * 问诊-查询订单详情信息-找医生、极速问诊和开药问诊
 * @param orderId 订单id
 * @returns Promise对象
 */
export const getConsultOrderDetailAPI = (orderId: string) =>
  request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', { orderId })

/**
 * 消息通知-所有未读数量
 * @returns 
 */
export const getUnkonwAPI = () => 
  request<number>('/patient/message/unRead/all')

/**
 * 查看处方
 * @param id 
 * @returns 
 */
export const getPrescriptionPicAPI = (id: string) =>
  request<Image>(`/patient/consult/prescription/${id}`)

/**
 * 问诊-订单-评价医生
 * @param data 
 * @returns 
 */
export const evaluateConsultOrderAPI = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}) =>
  request<{id: string}>('/patient/order/evaluate', 'POST', data)

/**
 * 问诊记录-订单列表-找医生、极速问诊、开药问诊
 * @param params 
 * @returns 
 */
export const getConsultOrderListAPI = (params: ConsultOrderListParams) => 
  request<ConsultOrderPage>('/patient/consult/order/list', 'GET', params)

/**
 * 订单-取消订单
 * @param id 
 * @returns 
 */
export const cancelOrderAPI = (id: string) => 
  request(`/patient/order/cancel/${id}`, 'PUT')

/**
 * 订单-删除订单
 * @param id 
 * @returns 
 */
export const delelOrderAPI = (id: string) =>
  request(`/patient/order/${id}`, 'DELETE')